package com.demo.service.impl;

import com.demo.entity.Area;
import com.demo.mapper.AreaMapper;
import com.demo.service.AreaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Ymj
 * @since 2020-11-23
 */
@Service
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements AreaService {

    private AreaMapper areaMapper;
    @Autowired
    public void setAreaMapper(AreaMapper areaMapper) {
        this.areaMapper = areaMapper;
    }
    @Override
    public void addCount(Long areaId) {
        Area area = areaMapper.selectById(areaId);
        area.setNumber(area.getNumber()+1);
        areaMapper.updateById(area);
    }
    @Override
    public void subCount(Long areaId) {
        Area area = areaMapper.selectById(areaId);
        if (area.getNumber()>0)
        area.setNumber(area.getNumber()-1);
        areaMapper.updateById(area);
    }
}
